package com.hue.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hue.entity.CrmBanner;
import com.hue.entity.R;
import com.hue.service.CrmBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author 姚凤桥
 * @since 2021-07-03
 */
@RestController
@RequestMapping("/crm-banner/front")
@CrossOrigin
public class CrmBannerFrontController {
    @Autowired
    private CrmBannerService crmBannerService;

    //分页查询
    @GetMapping("/findPage/{page}/{size}")
    public R findPage(@PathVariable("page") int page,
                      @PathVariable("size") int size) {
        Page<CrmBanner> crmBannerPage = new Page<>(page, size);
        crmBannerService.page(crmBannerPage, null);
        return R.ok().data("crmBannerPage", crmBannerPage);
    }

    //查询全部
    @GetMapping("/findAll")
    public R findAll(){
        List<CrmBanner> banners = crmBannerService.findOrderBySort();
        return R.ok().data("banners",banners);
    }
}

